package com.info.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class SelectProvice {
	public static void main(String[] args) {
		String path = "F:\\test2\\t.txt";
//		String path2 = "F:\\test2\\2.txt";
		File file = new File(path);
//		File file2 = new File(path2);
		BufferedReader br = null;
//		BufferedWriter bw = null;
		
		try {
			FileInputStream fis = new FileInputStream(file);
//			FileOutputStream fos = new FileOutputStream(file2);
			Map<String, List<String>> map = new TreeMap<String, List<String>>();
			
			InputStreamReader isr = new InputStreamReader(fis,"GBK");
//			OutputStreamWriter osw = new OutputStreamWriter(fos,"GBK");
			
			br = new BufferedReader(isr);
//			bw = new BufferedWriter(osw);
			
			String line = "";
			while((line = br.readLine())!= null) {
				
				line = line.trim();
				String[] str = line.split("\t   ");
				if(str[0].endsWith("0000")) {
					List<String> list = new ArrayList<String>();
					list.add(str[1]);
					list.add("0");
					map.put(str[0], list);
				}
				if(str[0].endsWith("00") && !str[0].endsWith("0000")) {
					String province = str[0].substring(0, 2)+"0000";
					if(map.containsKey(province)) {
						List<String> li = map.get(province);
						int i = Integer.valueOf(li.get(1));
						li.set(1, i+1+"");
						map.put(province, li);
					}
				}
			}
			
			for (String string : map.keySet()) {
				System.out.println("=="+string+"=="+map.get(string).get(0)+"=="+map.get(string).get(1));
			}
//			osw.flush();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				if(br!=null) {
					br.close();
					br= null;
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			
//			try {
//				if(bw!=null) {
//					bw.close();
//					bw= null;
//				}
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
		}
		
	}
}
